﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace SSLCertAutoUpdate
{
    //****************************************//
    // creater  zy
    // datetime 2023-09-04 14:26:53
    //****************************************//	
    class AppConfig
    {
        /// <summary>
        /// 证书路径
        /// </summary>
        public string CertPath { get; set; }
        /// <summary>
        /// 服务名称，检查完证书重启服务
        /// </summary>
        public string ServerName { get; set; }

        /// <summary>
        /// Openssl路径
        /// </summary>
        public string OpensslPath { get; set; }

        /// <summary>
        /// 创建证书命令
        /// </summary>
        public string CreateCertCmd { get; set; }
        /// <summary>
        /// 证书信息
        /// </summary>
        public string CertSubject { get; set; }
        /// <summary>
        /// 更新间隔，单位天
        /// </summary>
        public int UpdateInterval { get; set; } = 180;

        public string ServerCertName { get; set; } = "server.pem";
        public string ServerKeyName { get; set; } = "serkey.pem";

        public AppConfig()
        {
            Init();
        }

        private void Init()
        {
            try
            {
                var appSettings = ConfigurationManager.AppSettings;
                CertPath = appSettings.Get("CertPath");
                ServerName = appSettings.Get("ServerName");
                OpensslPath = appSettings.Get("OpensslPath");
                CreateCertCmd = appSettings.Get("CreateCertCmd");
                CertSubject = appSettings.Get("CertSubject");
                ServerCertName = appSettings.Get("CertName");
                ServerKeyName = appSettings.Get("KeyName");

            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("读配置失败。", ex);
            }
        }
    }
}
